package web.enumeditor;

import java.beans.PropertyEditorSupport;

public class SexTypeEnumEditor extends PropertyEditorSupport {

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        Sex result = null;
        if (null != text && !text.trim().equals(""))
            result = Sex.getSexByChineseName(text);
        if (null == result) {
            int val = Integer.parseInt(text);
            result = Sex.getSexByOrdinal(val);
        }
        if (result == null)
            throw new RuntimeException("性别不支持此种类型！");
        this.setValue(result);
    }
}
